package com.ruoyi.system.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.Members;
import com.ruoyi.system.domain.Order;

/**
 * 订单Mapper接口
 * 
 * @author 陈斌斌
 * @date 2025-09-29
 */
public interface OrderMapper extends BaseMapper<Order>
{
    /**
     * 查询订单
     * 
     * @param id 订单主键
     * @return 订单
     */
    default Order selectOrderById(String id){
        return new LambdaQueryChainWrapper<Order>(this)
                .eq(StringUtils.isNotEmpty(id),Order::getId,id)
                .one();
    };
    /**
     * 查询订单列表
     * 
     * @param order 订单
     * @return 订单集合
     */
    default List<Order> selectOrderList(Order order){
        return new LambdaQueryChainWrapper<Order>(this)
                .eq(StringUtils.isNotEmpty(order.getIsMember()),Order::getIsMember,order.getIsMember())
                .eq(StringUtils.isNotEmpty(order.getMethod()),Order::getMethod,order.getMethod())
                .between(StringUtils.isNotNull(order.getBeginCreateTime()), Order::getUpdateTime,order.getBeginCreateTime(),order.getEndCreateTime())
                .orderByDesc(Order::getUpdateTime)
                .list();
    };
    default Order selectMembersByLast(){
        return new LambdaQueryChainWrapper<Order>(this)
                .orderByDesc(Order::getCreateTime).last("limit 1").one();
    }
}
